package com.freesky.biz.report.controller;

import com.fasterxml.jackson.databind.ser.Serializers;
import com.freesky.biz.activity.domain.TStockMonitor;
import com.freesky.biz.activity.service.IStockMonitorService;
import com.freesky.biz.report.domain.TReportDayStock;
import com.freesky.biz.report.domain.TReportProject;
import com.freesky.biz.report.service.IReportDayStockService;
import com.freesky.common.annotation.Log;
import com.freesky.common.core.controller.BaseController;
import com.freesky.common.core.domain.AjaxResult;
import com.freesky.common.core.page.TableDataInfo;
import com.freesky.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/report/day/stock")
public class ReportDayStockController extends BaseController {

    @Autowired
    private IReportDayStockService reportDayStockService;

    @PreAuthorize("@ss.hasPermi('report:project:list')")
    @GetMapping("/projectList")
    public TableDataInfo projectList(TReportProject entity) {
        startPage();
        List<TReportProject> list = reportDayStockService.selectReportProjectList(entity);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('report:project:list')")
    @GetMapping("/summary")
    public AjaxResult summary(TReportProject entity) {
        return AjaxResult.success(reportDayStockService.selectSummaryReportProject(entity));
    }

    @PreAuthorize("@ss.hasPermi('report:daystock:list')")
    @GetMapping("/list")
    public TableDataInfo list(TReportDayStock entity) {
        startPage();
        List<TReportDayStock> list = reportDayStockService.findList(entity);
        return getDataTable(list);
    }

    @Log(title = "报表统计", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('report:daystock:export')")
    @GetMapping("/export")
    public AjaxResult export(TReportDayStock entity,
                             HttpServletResponse response) {
        return reportDayStockService.exportFile(entity);
    }

    /**
     * 取最新的项目关联批次号信息
     * @param entity
     * @return
     */
    @PreAuthorize("@ss.hasPermi('report:project:list')")
    @GetMapping("/reportByDayList")
    public AjaxResult reportByDayList(TReportDayStock entity) {
        return AjaxResult.success(reportDayStockService.selectReportByDayList(entity));
    }

}
